<?php

namespace App\Http\Controllers\WorkFlow;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\ProcessFlow;
use Illuminate\Http\Request;

class WorkFlowController extends Controller
{
    use ResponseData;
    //
    public function getList(ProcessFlow $model,Request $request){
        $data = $model->where('flow_id','>',0)->get();
        return $this->success($data);
    }

    /**
     * @param WorkFlow $model
     * @param Request $request
     * @return mixed
     * 创建了工作流
     */
    public function create(ProcessFlow $model,Request $request){
        $data = $request->only('flow_name','description','version','status','start','end');
        $respone = $model->query()->create($data);
        return $this->success($respone);
    }
    // 添加或更新工作流
    public function save(ProcessFlow $model,Request $request){
        $data = $request->only('flow_name','description','version','status','start','end');
        if($request->filled('id')){
            $flow = $model->query()->find($request->id);
            if(!$flow){
                return $this->failed('未获取工作流',201);
            }
            $flow->update($data);
            return $this->success($flow);
        }
        $result = $model->query()->create($data);
        return $this->success($result);
    }
}
